#! /usr/bin/env python

print "Harris corner detector"

import sys
import cv

if __name__ == '__main__':
    if len(sys.argv) > 1:
		img = cv.LoadImageM(sys.argv[1], cv.CV_LOAD_IMAGE_GRAYSCALE)
		eig_image = cv.CreateMat(img.rows, img.cols, cv.CV_32FC1)
		temp_image = cv.CreateMat(img.rows, img.cols, cv.CV_32FC1)
	
		maxx = 0
		ang = 0
		for i in range(0, 50, 5):
			img = cv.LoadImageM("camera_0_0_" + str(i) + ".png", cv.CV_LOAD_IMAGE_GRAYSCALE)
			c = len(cv.GoodFeaturesToTrack(img, eig_image, temp_image, 5000, 0.04, 1.0, useHarris=True))
			if c > maxx:
				maxx = c
				ang = i
		
		print "(camera 1) max number of corners found at view angle: " + str(ang) + " with " + str(maxx) + " corners"
		
		maxx = 0
		for j in range(10, 50, 5):
			for k in range(0, 50, 5):
				c = [0, 0]
				
				for i in [1, 2]:
					img = cv.LoadImageM("camera_" + str(i) + "_" + str(j) + "_" + str(k) + ".png", cv.CV_LOAD_IMAGE_GRAYSCALE)
					c[i - 1] = len(cv.GoodFeaturesToTrack(img, eig_image, temp_image, 5000, 0.04, 1.0, useHarris=True))
					
				s = sum(c)
				if s > maxx:
					maxx = s
					ang = (j, k)
					
		print "(camera 2,3) max number of corners found at view angle: " + str(ang)

